home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d20 / dorskel2.arc / XBBSMSG.ARC / WRITLINE.C < prev    next >
C/C++ Source or Header  |  1991-12-05  |  2KB  |  72 lines

  1. #include <os2.h>
  2. #include <string.h>
  3.  
  4.  
  5.  
  6. /* Return a line from a message */
  7.  
  8. char * _fastcall write_line (char *line, char **text,
  9.                              unsigned int linelen, int ctla) {
  10.  
  11.     register unsigned int x = 0;
  12.     char  *p;
  13.     char  *pp;
  14.  
  15.  
  16.     *line = 0;
  17.     if(!*text) return "";
  18.  
  19.     p = *text;
  20.     while(*p == '\n' || *p == '\x8d') p++;  /* skip junk */
  21.     while(*p == '\01' && !ctla) {           /* skip ctrl lines */
  22.         while(*p != '\r' && *p) p++;
  23.         while(*p == '\r' || *p == '\n' || *p == '\x8d') p++;
  24.     }
  25.     *text = p;  /* set to start of what will be displayed */
  26.  
  27.     if(!**text) return *text;
  28.     pp = line;
  29.     while(++x < (linelen + 1) && *p && *p != '\r') {
  30.         if(*p == '\n' || *p == '\x8d') {
  31.             p++;
  32.             x--;
  33.             continue;
  34.         }
  35.         *pp = *p;
  36.         p++;
  37.         pp++;
  38.         *pp = 0;
  39.     }
  40.     if(*p == '\r') {
  41.         *pp = 0;
  42.         p++;
  43.     }
  44.     else if(*p == ' ') {
  45.         *pp = 0;
  46.         while(*p == ' ') p++;
  47.     }
  48.     else if(x == (linelen + 1)) {
  49.         if(strchr(line,' ')) {
  50.             while(p > *text && *pp != ' ') {
  51.                 *pp = 0;
  52.                 pp--;
  53.                 p--;
  54.             }
  55.             if(p == *text) {
  56.                 strncpy(line,*text,linelen + 1);
  57.                 line[linelen + 1] = 0;
  58.                 p = text[linelen + 1];
  59.             }
  60.             else p++;
  61.         }
  62.     }
  63.     while(*pp == ' ' && pp > line) {    /* Rstrip returned string */
  64.         *pp = 0;
  65.         --pp;
  66.     }
  67.  
  68.     pp = *text;
  69.     *text = p;
  70.     return pp;
  71. }
  72.